<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

<script>
    // 1、用构造函数的方式
    let color = new Array('blue', 'red', 'pink')
        // 2、采用数组字面量
    let fruit = ['peach', 'orange', 'apple']

    // 读取
    let result = fruit[1]

    // 多种类型元素的数值都可以放和java，c不一样
    // 数组长度用.length
    console.log(fruit.length);

    // 添加元素
    let arr = [];
    arr[0] = 10;
    arr[4] = 20;
    // 缺点空间浪费
    // 替换
    fruit[2] = 'lemon';
    console.log(fruit);

    // 数组遍历
    for (let i = 0; i < fruit.length; i++) {
        console.log(fruit[i]);
    }

    let arr2 = [145, 254, 323, 4, 52, 12, 443, 562, 354, 32]
    let a = arr2[1];
    for (let i = 0; i < arr2.length; i++) {
        if (a >= arr2[i]) {
            a = arr2[i]
        }
    }
    console.log(a);


    // 冒泡排序
    let temp;
    let arr3 = [2, 3, 1, 4, 56, 5, 7]
    for (let i = 0; i < arr3.length - 1; i++) {
        for (let j = 0; j < arr3.length - 1 - i; j++) {
            if (arr3[j] < arr3[j + 1]) {
                temp = arr3[j + 1];
                arr3[j + 1] = arr3[j];
                arr3[j] = temp;
            }
        }
    }
    console.log(arr3.toString());

    // for of 循环练习
    for (let item of arr3) {
        console.log(item);
    }

    // 二维数组
    let arr4 = [][4]
</script>

</html>